# Contributor: Jeff Pohlmeyer <yetanothergeek@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=gpm
pkgver=1.20.7
pkgrel=4
pkgdesc="A mouse server for the console"
options="!check" # No testsuite
url="https://www.nico.schottelius.org/software/gpm/"
arch="all"
license="GPL-2.0-or-later"
depends_dev="$pkgname-libs"
makedepends="$depends_dev texinfo autoconf automake libtool bison linux-headers
	ncurses-dev"
subpackages="$pkgname-dev $pkgname-doc $pkgname-libs $pkgname-utils
	$pkgname-openrc"
source="http://www.nico.schottelius.org/software/gpm/archives/gpm-$pkgver.tar.bz2
	error-format.patch
	fix-highly-illegal-return-of-in-as-char.patch
	fix-signedness-issue.patch
	install-shared-libs-with-+x-perms.patch
	install-unversioned-solibrary.patch
	musl-fixes.patch
	constify-format-strings.patch
	gpm-include-sysmacros.patch
	gcc-10.patch

	$pkgname.initd
	$pkgname.confd
	"

# Fix build with gcc >= 10
export CFLAGS="$CFLAGS -fcommon"

prepare() {
	default_prepare
	./autogen.sh
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--disable-static
	export CPPFLAGS="$CPPFLAGS -I$builddir/src/headers"
	make
}

package() {
	make DESTDIR="$pkgdir" install

	# Create solink
	ln -s libgpm.so.2.1.0 "$pkgdir"/usr/lib/libgpm.so

	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
}

utils() {
	depends="$pkgname"
	pkgdesc="Mouse utilities for console"
	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr/
	rmdir "$pkgdir"/usr/lib
}

sha512sums="
51c1141ed502f8b6bc846485a8e315bafe3cf2b7c9d1ea8a710d9748ff2058f29c7ab5715fc1730a8437c613181d2050f37b134e9288c69ba8ff7fb0be7ec0d1  gpm-1.20.7.tar.bz2
b4a883cb3a5b3977e0ba3909d68335b5543ae3a7d9aaa704ec82693a474813996cc6822a086737da17c67e2c2b827e3d4a48ec27d9c82f3070f75c1126651896  error-format.patch
15c4f1459a28c931362a4f6cd22278b52c998b3b6f7164ee2e0dbd88fdace74b5e3599d3f3ac665c1df79a6ece14faac2b35f57d5d834a7714de2419954e6b5f  fix-highly-illegal-return-of-in-as-char.patch
db7e02b50bb02726ca743d2c7bef7d49edb359bb1594cc18f371662471d425a32f5c9f99743f237046b5a3534d2c6257fdd5cb6d9e08824c6d84725b7ddf0272  fix-signedness-issue.patch
ec21b7029e0880b342bca5a70522e33d5cabbf77c44c1dd23b16d829d8fcc6cadcdf77b01724a91a6640916673f6d5ab91d18db4cd709ed77f9ce22dec723a13  install-shared-libs-with-+x-perms.patch
05bdf6a03870175dcee5414d6d2d434b6cd3e06686f0be22d70fc7f9759db8ccea0bf9ae900d95e6d2872845cd66ee0a794afc5ece78c6640be163cad2065c58  install-unversioned-solibrary.patch
45d3a20a8f9f00f78b21c10143e138add17d414e9b5ecc28d9efee9c2190450c79dca00b13a8247ee7753ff778b09bc88fe8c512366d5b1622981bb5d612f933  musl-fixes.patch
36a5059c6336010b504ec6fc53c2d3df0811b1f1249c0e04c13066db06667119377a21e58121aaa8d4b620be2a5c21da0b018f168e36a44f85802cc50c936ba5  constify-format-strings.patch
62d294f900ba1922119ebc87f97e86b1653647e03576c982011bf4f629332cc703f3994d5cc4b9bf2dac3c18636a61e420000d16cfdc7c284185c9442cce5b64  gpm-include-sysmacros.patch
8de69783f14a2f686eb96d91d2761c879367b14f68801283cd415849f05253686cd11170971f21e5ddc932c02b0621d4aa528ff497a69d27daf29debf896f3ea  gcc-10.patch
d268504bd0cf83706863a8af5c5719b0d192c34ae6a78ff0378521841eca242b39a6e6891080a5fc5512732f84e7439697ba92bfda3ecc1aaebd36b16e946477  gpm.initd
0e7c96f29222d33301fc9c5c8cf409b7dbe6cbb1e79d76444ae5724e8b793679d3ea597a8ad64187e85680799847632095e469445ae56f893616cb0235a29f3a  gpm.confd
"
